<template>
  <div class="mod-menu">
    <div class="mb30">
      <!-- <el-button type="primary" @click="addOrUpdateHandle()">添加属性</el-button> -->
      <el-button type="primary" @click="attributeValue()">新增规格</el-button>
    </div>
    <el-table :data="dataList" border style="width: 100%; " row-key="id" :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
      <!-- <el-table-column prop="id" align="center" label="编号">
      </el-table-column> -->
      <el-table-column prop="name" align="center" label="属性名称">
      </el-table-column>
      <el-table-column prop="order_index" align="center" label="排序">
      </el-table-column>
      <el-table-column fixed="right" header-align="center" align="center" label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="attributeValue(scope.row.id,scope.row.parent_sku_id)">修改</el-button>
          <el-button type="text" size="small" class="c-error" @click="addOrUpdateHandle(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 弹窗, 新增 / 修改 -->
    <property-value v-if="propertyValue" ref="propertyValue" @successUp='successUp'></property-value>
  </div>
</template>

<script>
import serviceApione from '@/api/serviceApione.js'
import propertyValue from './property-value.vue'
export default {
  data () {
    return {
      dataForm: {},
      dataList: [

      ],
      dataListLoading: false,
      propertyValue: false
    }
  },
  components: {
    propertyValue
  },
  mounted () {
    this.dataListF()
  },
  methods: {
    successUp (e) {
      if (e) {
        this.dataListF()
      }
    },
    dataListF () {
      serviceApione.getSkuAll().then(res => {
        if (res.data.code == 200) {
          this.dataList = res.data.list
        }
      })
    },
    // 新增 / 修改
    attributeValue (id, parent_sku_id) {
      this.propertyValue = true
      this.$nextTick(() => {
        this.$refs.propertyValue.init(id, parent_sku_id)
      })
    },
    addOrUpdateHandle (id) {
      this.$confirm('此操作将永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        serviceApione.delSku(id).then(res => {
          if (res.data.code == 200) {
            this.dataListF()
            this.$message({
              type: 'success',
              message: '删除成功!'
            })
          }
        })
      }).catch(() => {

      })
    }
  }
}
</script>
<style lang="scss">
.mb30 {
  margin-bottom: 30px;
}
</style>
